<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:data="http://www.w3.org/1999/xhtml">
<head>
    <!--<meta content="text/html;charset=UTF-8"/>-->
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <meta name="viewport" content="width=device-width, initial-scale=1"/>
</head>
<head th:include="include/include"></head>
<style>
    <!--修改验证图标位置-->
    .form-group .form-control-feedback {
        top: 0;
        right: -30px;
    }
</style>
<body>
<div class="container-fluid">
    <form role="form"   action="case/save" method="post" id="myform">
        <div class="row text-left margin10top">
            <div class="col-md-4 col-sm-4 col-xs-4 form-inline">
                <div class="form-group form-inline margin20Left">
                    <label>案件编号:</label>
                    <input value="" name="caseNo" id="caseNo" class="form-control" style="width: 200px;"/>
                </div>
            </div>
            <div class="col-md-4 col-sm-4 col-xs-4 form-inline ">
                <div class="form-group form-inline">
                    <label>案件负责人:</label>
                    <label>
                        <select name="caseHuman" value="" class="form-control">
                            <option value="15">张三</option>
                            <option value="13">李四</option>
                        </select>
                    </label>
                </div>
            </div>
            <div class="col-md-4 col-sm-4 col-xs-4 form-inline">
                <div class="form-group form-inline">
                    <label>报案人:</label>
                    <input name="informant" value="" class="form-control" style="width: 100px;"/>
                </div>
            </div>
        </div>

        <div class="row text-left margin20top">
            <div class="col-md-4 col-sm-4 col-xs-3 form-inline">
                <div class="form-group form-inline margin20Left">
                    <label>是否电话销售:</label>
                    <label role="radio"><input type="radio" value="1" name="isTelSale" id="yesTelSale" checked/>是</label>
                    <label role="radio"><input type="radio" value="0" name="isTelSale" id="noTelSale"/>否</label>
                </div>
            </div>
            <div class="col-md-4 col-sm-4 col-xs-4 form-inline ">
                <div class="form-group form-inline">
                    <label>车牌号:</label>
                    <input value="" name="licenseNo" class="form-control" style="width:150px;"/>
                </div>
            </div>
            <div class="col-md-4 col-sm-4 col-xs-4 form-inline ">
                <label>保险公司:</label>
                <label>
                    <select name="insureCor" class="form-control">
                        <option value="中国人寿">中国人寿</option>
                        <option value="太平洋">太平洋</option>
                        <option value="平安">平安</option>
                    </select>
                </label>
            </div>
        </div>
        <div class="row margin20top">
            <div class="col-md-4 col-sm-4 col-xs-4 form-inline ">
               <div class="form-group form-inline margin20Left">
                   <label>联系电话:</label>
                   <label><input value="" name="linkTel" class="form-control" style="width: 150px;"/></label>
               </div>

            </div>
            <div class="col-md-4 col-sm-4 col-xs-4 form-inline ">
                <div class="form-group form-inline">
                    <label>案件接待人:</label>
                    <input value="" name="caseHandler" class="form-control" style="width: 150px;"/>
                    <label class=""></label>
                </div>
            </div>
            <div class="col-md-4 col-sm-4 col-xs-4 form-inline ">
                <div class="form-group form-inline ">
                    <label>定损员:</label>
                    <label>
                        <select name="fixedLosser" value="" class="form-control" id="fixedLosser">
                        </select>
                    </label>
                </div>

            </div>
        </div>
        <div class="row margin20top">
            <div class="col-md-4 col-sm-4 col-xs-4 form-inline ">
                <div class="form-group form-inline margin20Left">
                    <label>派工时间:</label>
                    <label>
                        <div class="input-append date"  >
                            <input style="width: 200px;" class="form-control" name="dispatchingTime" id="dispatchingTime" size="16" type="text" data-date-format="dd-mm-yyyy" value="" readonly>
                            <span class="add-on"><i class="icon-th"></i></span>
                        </div>
                    </label>
                </div>
            </div>

            <div class="col-md-4 col-sm-4 col-xs-4 form-inline ">
                <div class="form-group form-inline">
                    <label>核损员:</label>
                    <label>
                        <select name="verityLosser" value="" class="form-control" id="verityLosser">
                        </select>
                    </label>
                </div>
            </div>

        </div>
        <div class="row margin20top">
            <div class="col-md-12 col-sm-12 col-xs-12 form-inline">
                <div class="form-group form-inline margin20Left">
                    <label>案发地:</label>
                    <label id="distpicker" class="form-inline">
                        <label for="province">省:</label>
                        <select name="accidentPlaceProvince" id="province" class="form-control input-sm"></select>
                        <label for="city">市:</label>
                        <select name="accidentPlaceCity" id="city" class="form-control input-sm"></select>
                        <label for="district">区:</label>
                        <select name="accidentPlaceDistrict" id="district" class="form-control input-sm"></select>
                    </label>
                    <label class="" style="width: auto;">详细地址:
                        <input value="" name="address" class="form-control" style="width: 150px;"/>
                    </label>
                    <label class="" id="tip"></label>
                </div>

            </div>
        </div>
        <div class="row text-center margin20top">
            <div class="col-md-12 col-xs-12 col-sm-12">
                <button type="button" id="save" class="btn-group-lg btn-info" style="font-size: 25px;" >保存</button>
                <button type="button" id="restart" class="btn-group-lg btn-info" style="font-size: 25px;margin-left: 20px;" onclick="resetData();" >重置</button>
            </div>
        </div>
    </form>

</div>

</body>
<script>
    //禁止滚动条
    $(document.body).css({
        "overflow-x":"hidden",
        "overflow-y":"auto"
    });
    $(function () {
        //datetimepicker
        // $('#dispatchingTime').datetimepicker("setStartDate","2018-01-01");
        $('#dispatchingTime').datetimepicker({
            "format": 'yyyy-mm-dd hh:ii:ss'
            ,"language":"zh-CN",
            weekStart: 1, //一周从哪一天开始
            todayBtn:  "linked",
            autoclose: 1,
            todayHighlight: 1,
            startView: 2,
            forceParse: 0,
            showMeridian: 1
            // ,"startDate":"2018-01-01"
            ,initialDate: new Date()
        });

        var myform=$("#myform");
        $("#save").click(function(){
            var url = myform.attr("action");
            console.log(url);
            $("#myform").data('bootstrapValidator').validate();
            if ($("#myform").data('bootstrapValidator').isValid()) {//获取验证结果，如果成功，执行下面代码
                //清楚验证规则
                $("#myform").data('bootstrapValidator').destroy();
                $("#myform").data('bootstrapValidator',null);
                $.post(url,$("#myform").serialize(),function(data){
                    alert(data.msg);
                    resetData();/*重置数据*/
                    formValidator();
                });
            }else{
                alert("信息未填写完整");
            }

        });

        //获取案件编号
        var caseNo=getMaxCaseNo();
        $("#caseNo").val(caseNo);
        //设置初始地址
        $("#distpicker").distpicker({
            province: "江苏省",
            city: "南京市",
            district: "鼓楼区"
        });
        //初始化表单
        formValidator();
        getlosser("1");
    })
    //初始化表单
    function formValidator(){
        //    form表单验证
        $("form").bootstrapValidator({
            live:"disabled",/*验证时机，enabled是内容有变化就验证（默认），disabled和submitted是提交再验证*/
            message:"通用的验证失败信息",
            // submitButtons: '#save1',//指定提交按钮，如果验证失败则变成disabled，
            feedbackIcons:{//根据验证结果显示的各种图标
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields:{
                caseNo:{
                    message: '用户名验证失败',
                    validators:{
                        notEmpty: {
                            message: '用户名不能为空'
                        }
                        //, stringLength: {
                        //     min: 6,
                        //     max: 18,
                        //     message: '用户名长度必须在6到18位之间'
                        // }
                    }
                },
                address:{
                    message:"验证失败",
                    validators:{
                        notEmpty: {
                            message: '请填写具体地址'
                        }
                    }
                },
                caseHuman:{
                    validators:{
                        notEmpty: {
                            message: '请选择负责人'
                        }
                    }

                },
                informant:{
                    validators:{
                        notEmpty: {
                            message: '请填写办案人'
                        }
                    }

                },
                linkTel:{
                    validators:{
                        notEmpty: {
                            message: '请填写联系电话'
                        }
                    }

                },
                licenseNo:{
                    validators:{
                        notEmpty: {
                            message: '请填写车牌号'
                        }
                    }

                },
                caseHandler:{
                    validators:{
                        notEmpty: {
                            message: '请填写案件接待人'
                        }
                    }

                },
                dispatchingTime:{
                    trigger:'change',
                    validators:{
                        notEmpty: {
                            message: '请填写派工时间'
                        }
                        ,date:{
                        format : 'YYYY-MM-DD HH:mm:ss',
                        message : '日期格式不正确'
                    }
                    }

                },
                fixedLosser:{
                    validators:{
                        notEmpty: {
                            message: '请选择定损员'
                        }
                    }

                },
                verityLosser:{
                    validators:{
                        notEmpty: {
                            message: '请选择核损员'
                        }
                    }

                }
            }
        })

    }
    function resetData() {
        var myInput = document.getElementById("caseNo");
        var caseNo=getMaxCaseNo()
        myInput.defaultValue = caseNo;
        document.forms[0].reset();
    }
    //获取案件编号
    function getMaxCaseNo() {
        var caseNo="";
        $.ajax({
            url:"caseNO/findMaxNo",
            dataType:"json",
            type:"get",
            data:{flag:"100"},
            async: false,
            success:function (data) {
                caseNo= data.data;
            },error: function(XMLHttpRequest, textStatus, errorThrown) {
                alert("error")
            }});

        return caseNo;
    }
    //获取核损人
    function getlosser(flag) {
        if(flag==="1"){//核损人
            $.get("user/query",{"flag":"1"},function(data){
                var str="<option value=''>-请选择-</option>";
                $.each(data,function(index,item){
                    str+="<option value='"+item.id+"'>"+item.userName+"</option>";
                });
                $("#fixedLosser").append(str);
                $("#verityLosser").append(str);


            });

        }
        
    }
</script>
</html>